﻿using CIS.Common.Grpc.Protos;
using Grpc.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace CIS.Common.Grpc
{
    public class GrpcServer : IGrpcServer
    {
        private GrpcServiceBase _grpcService;
        public Func<GrpcMessage, Task> OnDataRecivedAsync { get; set; }

        public GrpcServer(GrpcServiceBase grpcServiceBase)
        {
            _grpcService = grpcServiceBase;
            _grpcService.OnReceiveAsync = OnDataRecive;
        }

        private async Task OnDataRecive(GrpcMessage message)
        {
            OnDataRecivedAsync.Invoke(message);
        }

        public async Task<GrpcMessage> RequestAsync(string clientName, GrpcMessage message, int timeOut = 3000)
        {

            return await _grpcService.ServerSendMsg(clientName, message);
        }

    }
}
